package com.googlecode.rjm.model.journal;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.googlecode.rjm.model.Persistent;
import com.googlecode.rjm.model.User;


@Entity
@Table(name="journals")
@DiscriminatorColumn(name = "journalized_type", discriminatorType = DiscriminatorType.STRING)
public class Journal extends Persistent {
	
	@Id
	private Integer id;
	
	/*
	Doing this way does not allow inverse mapping, so the Issue could not have a list of journals
	
	@Any(metaColumn = @Column(name = "journalized_type"))  
	@AnyMetaDef(idType = "integer",
				metaType = "string",
				metaValues = {  
					@MetaValue(value = "Issue", targetEntity = Issue.class),  
					//@MetaValue(value = "Board", targetEntity = Board.class) 
				}
	)
	@JoinColumn(name="journalized_id")
	private Journalized journalized;
	*/
	
	@ManyToOne
	@JoinColumn(name="user_id")
	@Fetch(FetchMode.SELECT)
	private User user;
	
	private String notes;
	
	@Column(name="created_on")
	private Date creationDate;
	
	//@Transient
	@OneToMany//(mappedBy="journal")
	@JoinColumn(name="journal_id")
	private List<JournalDetail> details;

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getNotes() {
		return this.notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public Date getCreationDate() {
		return this.creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public List<JournalDetail> getDetails() {
		return this.details;
	}

	public void setDetails(List<JournalDetail> details) {
		this.details = details;
	}

}
